package com.bdqn.t382.lx.service.impl;

import com.bdqn.t382.lx.mapper.AnimalsMapper;
import com.bdqn.t382.lx.pojo.Animals;
import com.bdqn.t382.lx.pojo.Page;
import com.bdqn.t382.lx.pojo.SysUser;
import com.bdqn.t382.lx.service.AnimalsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AnimalsServlet implements AnimalsService {
    @Autowired
    AnimalsMapper animalsMapper;

    @Override
    public SysUser getLogin(String account, String password) {
        return animalsMapper.getLogin(account, password);
    }

    @Override
    public Long count() {
        return animalsMapper.count();
    }
 
    @Override
    public List<Animals> getAnimalsList() {
        return animalsMapper.getAnimalsList();
    }


    @Override
    public Page getPage(Integer pageNo, Integer pageSize, String ani_name) {
        Page page = new Page();
        try {
            page.setPageNo(pageNo);//当前页
            page.setPageSize(pageSize);//每页显示的数据量
            Long total = animalsMapper.count();//总记录数
            page.setTotalCount(total.intValue());
            int offset = (pageNo - 1) * pageSize;// 计算偏移量
            List<Animals> list = animalsMapper.getPage(offset, pageSize, ani_name);
            page.setAnList(list);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return page;
    }

    @Override
    public int insertAnimals(Animals animals) {
        return animalsMapper.insertAnimals(animals);
    }

    @Override
    public int deleteAnimals(int ani_id) {
        return animalsMapper.deleteAnimals(ani_id);
    }

    @Override
    public Animals viewAnimals(int ani_id) {
        return animalsMapper.viewAnimals(ani_id);
    }

    @Override
    public int updateAnimals(Animals animals) {
        return animalsMapper.updateAnimals(animals);
    }

    @Override
    public SysUser getSysuserById(int id) {
        return animalsMapper.getSysuserById(id);
    }
}
